<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class TbDocument
 * 
 * @property int $id
 * @property string $title
 * @property Carbon $create_date
 * @property string|null $introduction
 * @property string|null $thumbnail
 * @property string $docs
 * @property string $author
 * @property int $views
 * @property int|null $documents_classify_id
 * @property int $worker_id
 * @property Carbon|null $create_time
 * @property Carbon|null $update_time
 * 
 * @property TbDocumentsClassify|null $tb_documents_classify
 * @property Worker $worker
 * @property Collection|TbDocumentImg[] $tb_document_imgs
 * @property Collection|TbDocumentTag[] $tb_document_tags
 *
 * @package App\Models
 */
class TbDocument extends Model
{
	protected $table = 'tb_documents';

	protected $casts = [
		'views' => 'int',
		'documents_classify_id' => 'int',
		'worker_id' => 'int'
	];

	protected $dates = [
		'create_date'
	];

	protected $fillable = [
		'title',
		'create_date',
		'introduction',
		'thumbnail',
		'docs',
		'author',
		'views',
		'documents_classify_id',
		'worker_id'
	];

	public function tb_documents_classify()
	{
		return $this->belongsTo(TbDocumentsClassify::class, 'documents_classify_id');
	}

	public function worker()
	{
		return $this->belongsTo(Worker::class);
	}

	public function tb_document_imgs()
	{
		return $this->hasMany(TbDocumentImg::class, 'document_id');
	}

	public function tb_document_tags()
	{
		return $this->hasMany(TbDocumentTag::class, 'document_id');
	}
}
